#include "runner.h"
#include "window.h"
#include <QApplication>

Runner::Runner(): QThread(), threadRunning(false), msdelay(Widget::RunDelay)
{
}
Runner::~Runner()
{
    threadRunning = false;
    QApplication::processEvents();
}

void Runner::cont()
{
    start();
}

int Runner::delay()
{
    return msdelay;
}

QString Runner::delayStr()
{
    return QString("%1").arg(msdelay);
}

void Runner::step()
{
    emit execute();
}

void Runner::stop()
{
    threadRunning = false;
}

void Runner::run()
{
    threadRunning = true;
    while(threadRunning) {
        emit execute();
        msleep(msdelay);
        QApplication::processEvents();
    }
    emit rundone();
}

void Runner::setRunning(bool enable)
{
    threadRunning = enable;
}

bool Runner::running()
{
    return threadRunning;
}

void Runner::setDelay(int ms)
{
    msdelay = ms;
}

